package org.srtc.infopub.tools;

import java.util.HashMap;

interface ProtocolPaserInterface {

	public String getQueryField(String query, String field);

}


class Config {
	
	public static HashMap<String, Integer> getConf() {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("Protocol", 0);
		map.put("coal", 1);
		map.put("exceptProtocol", 2);
		map.put("exceptCoal", 3);
		
		return map;
	}
}


public class ProtocolPaser implements ProtocolPaserInterface{

	@Override
	public String getQueryField(String query, String field) {
		// TODO Auto-generated method stub
		HashMap<String, Integer> map = Config.getConf();
		Integer val = map.get(field);
		if (val == null) return null;
		
		String[] strs = query.split("\\.");
		if (strs.length < 2) {
			return null;
		}
		String pro = strs[0];
		String coal = strs[1];
		String exProCoal = "";
		if (strs.length > 2) {
			for (int i = 2; i<strs.length; i++) {
				exProCoal = exProCoal + strs[i] + ".";
			}
		}
		String exPro = coal + "." + exProCoal;
		
		switch(val) {
		case 0:
			return pro;
		case 1:
			return coal;
		case 2:
			return exPro;
		case 3:
			return exProCoal;
		default:
			return null;
		}
	}
	
	public static void main(String[] args) {
		ProtocolPaser pp = new ProtocolPaser();
		System.out.println(pp.getQueryField("PROTOCOL.001.", "coal"));
	}
	
}
